package com.wang.di.timer.anno_executor;

import com.wang.di.core.handler.AnnoHandler;
import com.wang.di.core.handler.JustMethodProxy;
import com.wang.di.timer.anno.Timer;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class TimerExecutor extends AnnoHandler<Timer> {
    @Override
    public JustMethodProxy method(Object instance, Class<?> clz, Method method, Timer anno) throws Exception {
        long s = anno.second();
        new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(s);
                    method.invoke(instance);
                } catch (InterruptedException | IllegalAccessException | InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        return null;
    }
}
